(function (aopc) {
    aopc.addExpandPage(824, function (get) {
        const Common = get('UtilsCommon', 'Common');
        return {
            expandInit() {
                this.subjectsProperty = this.getProperty('Subjects');
                this.subjectsProperty.initDataList = this.subjectInitDataList.bind(this);
                this.selectUserDialog1 = this.getProperty('selectUserDialog1');
                this.uploadFile1 = this.getProperty('uploadFile1');

                const last_step = this.getProperty('last_step');
                const seat_layout = this.getProperty('seat_layout');

                const container_view = this.getProperty('container_view');
                const isBook = this.pageData.IsBook === 'true';
                last_step.isVisible = isBook;
                seat_layout.isVisible = isBook;
                if (isBook) {
                    container_view.loadAction.dataAction.getEntityData = '';
                    container_view.properties[0].isUserName = false;
                }
                this.isBook = isBook;

                let url = this.pageData.ref === '2' ? '/bookMeetingEdit.html' : '/meetingHost.html';
                url += '?MeetingId=' + this.pageData.MeetingId;
                if (this.pageData.backUrl2) url += "&backUrl=" + encodeURIComponent(this.pageData.backUrl2);
                this.pageConfig.backUrl = url;
            },
            setReporter({ property }) {
                this.setDialogProperty(property, '选择汇报人', true, property.data.ReporterList);
            },
            setAttendUsers({ property }) {
                this.setDialogProperty(property, '选择列席人员', false, property.data.UserList);
            },
            setDialogProperty(property, title, isReporter, dataSource) {
                if (!property.obj) property.obj = {
                    setSelectUsers: () => {
                        this.setSelectUsers(property);
                    },
                    title,
                    isMultiple: true,
                    isReporter,
                    dataSource
                };
                this.selectUserDialog1.pageAxis.showUsersDialog(property.obj);
            },
            setSelectUsers(property) {
                const list = property.obj.dataSource;
                if (property.obj.isReporter) {
                    const p = property.properties[2];

                    const names = [];
                    const ids = [];
                    list.forEach(d => {
                        names.push((d.JobName || '') + d.Name);
                        ids.push(d.UserId);
                    })
                    property.data.Reporters = ids.join(',');

                    p.setValue(names);
                }
                else {
                    const p = property.properties[1];
                    p.setValue(`列席人员 ${list.length}`);
                    property.data.UserIds = list.map(m => m.UserId).join(',');
                }
            },
            subjectInitDataList() {
                this.isCurrents = [];
                this.isNexts = [];
            },
            setOnOffProperty(on_off_view, data) {
                const theme = this.theme;
                on_off_view.properties.forEach(p => {
                    if (p.name !== 'FileCount') {
                        p.isEdit = true;
                        p.setValue = function (v) {
                            this.value = v;
                            this.data[p.name] = this.value ? 1 : 0;
                            const p2 = this.properties[0];
                            if (theme === 'red') p2.style.backgroundColor = v ? '#F92A2A' : '#EECACA';
                            else p2.style.backgroundColor = v ? '#449AEB' : '#BAC8DC';
                            p2.style.justifyContent = v ? 'flex-end' : 'flex-start';
                            p2.refresh && p2.refresh();
                        };
                        if (p.name === 'IsCurrent') this.isCurrents.push(p);
                        else if (p.name === 'IsNext') this.isNexts.push(p);
                        if (data[p.name]) {
                            const p2 = p.properties[0];
                            if (theme === 'red') p2.style.backgroundColor = '#F92A2A';
                            else p2.style.backgroundColor = '#449AEB';
                            p2.style.justifyContent = 'flex-end';
                        }
                    }
                });
            },
            setSubjectProperties({ view, index, data, length }) {
                const p = this.getViewProperty(view, 'No');
                if (p) {
                    const i = index + 1;
                    p.text = i < 10 ? '0' + i : i;
                    if (p.setValue) setTimeout(() => p.setValue(p.text), 0);
                }

                const right_on_off_view = this.getViewProperty(view, 'right_on_off_view');
                if (this.isBook) right_on_off_view.isVisible = false;
                else this.setOnOffProperty(right_on_off_view, data);

                data.up_move1 = index > 0 ? '上移' : '';
                data.down_move1 = index < length - 1 ? '下移' : '';
                const up_move1 = this.getViewProperty(view, 'up_move1');
                const down_move1 = this.getViewProperty(view, 'down_move1');
                up_move1.setValue && setTimeout(() => up_move1.setValue(data.up_move1), 0);
                down_move1.setValue && setTimeout(() => down_move1.setValue(data.down_move1), 0);

                const fileCount = this.getViewProperty(view, 'FileCount');
                fileCount.isExpand = !!data.IsExpand;
                if (fileCount.isExpand) {
                    const files = this.getViewProperty(view, 'Files');
                    files.isVisible = true;
                }
            },
            setFileVisible({ property, view }) {
                if (!property.data.Files || property.data.Files.length === 0) {
                    property.disabled = true;
                    return;
                }
                property.setIsExpand();
                const files = view.getView().getView().properties[3];
                files.isVisible = !files.isVisible;
                files.setIsVisible(files.isVisible);
            },
            setFilesProperties({ view, index, data, length }) {
                data.up_move = index > 0 ? '上移' : '';
                data.down_move = index < length - 1 ? '下移' : '';
                const up_move = this.getViewProperty(view, 'up_move');
                const down_move = this.getViewProperty(view, 'down_move');
                up_move.setValue && setTimeout(() => up_move.setValue(data.up_move), 0);
                down_move.setValue && setTimeout(() => down_move.setValue(data.down_move), 0);

                const file_icon = this.getViewProperty(view, 'file_icon');
                if (file_icon) {
                    file_icon.imgUrl = this.getFileIcon(data);
                }
            },
            getFileIcon(data) {
                const t = data.FileType.toLowerCase();
                const vt = '.mp4,.mov,.avi,.mkv,.rmvb';
                const it = '.jpg,.jpeg,.png,.gif,.svg';
                if (t === '.doc' || t === '.docx') return "/images/yxinmt_h5/25080313563175553.png";
                else if (t === '.xls' || t === '.xlsx') return "/images/yxinmt_h5/25080313565026910.png";
                else if (t === '.ppt' || t === '.pptx') return "/images/yxinmt_h5/25080313564674186.png";
                else if (t === '.pdf') return "/images/yxinmt_h5/25080313563543435.png";
                else if (vt.indexOf(t) >= 0) return '/images/yxinmt_h5/25080521052203829.png';
                else if (it.indexOf(t) >= 0) return '/images/yxinmt_h5/25080521052598726.png';
                else return "/images/yxinmt_h5/25080521052936371.png";
            },
            setCurrentNextChecked(property, list1, list2) {
                list1.forEach(p => {
                    if (property !== p) p.setValue(false);
                });
                list2.forEach(p => {
                    if (p.data === property.data && p.value) {
                        p.setValue(false);
                        return false;
                    }
                });
            },
            setChecked({ property }) {
                property.setValue(!property.value);
                if (property.name === 'IsCurrent' && property.value) {
                    this.setCurrentNextChecked(property, this.isCurrents, this.isNexts)
                }
                else if (property.name === 'IsNext' && property.value) {
                    this.setCurrentNextChecked(property, this.isNexts, this.isCurrents)
                }
            },
            up_move_subject({ property }) {
                this.setUpDownIndex(property, this.subjectsProperty, true);
            },
            up_move_file({ property, view }) {
                const filesProperty = view.getView().getView();
                this.setUpDownIndex(property, filesProperty, true);
            },
            setUpDownIndex(property, listProperty, isUp) {
                const dataList = listProperty.getValue();
                const list = [];
                for (let i = 0; i < dataList.length; i++) {
                    const data = dataList[i];
                    if (i === property.dataIndex) {
                        if (isUp) {
                            list.push(data);
                            list.push(dataList[i - 1]);
                        }
                        else {
                            list.push(dataList[i + 1]);
                            list.push(data);
                        }
                    }
                    else if (!isUp && (i > property.dataIndex + 1 || i < property.dataIndex)) list.push(data);
                    else if (isUp && (i > property.dataIndex || i < property.dataIndex - 1)) list.push(data);
                }
                listProperty.setValue(list);
            },
            down_move_subject({ property }) {
                this.setUpDownIndex(property, this.subjectsProperty, false);
            },
            down_move_file({ property, view }) {
                const filesProperty = view.getView().getView();
                this.setUpDownIndex(property, filesProperty, false);
            },
            uploadCallback({ res, property }) {
                const files = property.getView().getView().properties[3];
                res.FileId = Common.createGuid();
                files.add(res);
            },
            showUploadFile({ property }) {
                this.uploadFile1.pageAxis.show(property);
            },
            setFiles(dataList, property) {
                const files = property.getView().getView().properties[3];
                files.addList(dataList);
            },
            expandSetEntityData({ entityData }) {
                const names = {};
                const subjects = entityData.Subjects;
                for (let i = 0; i < subjects.length; i++) {
                    const s = subjects[i];
                    if (Common.isNullOrEmpty(s.Name)) {
                        this.alert('请输入会议议题！')
                        return false;
                    }

                    if (!names[s.Name]) names[s.Name] = 0;
                    names[s.Name]++;
                    if (names[s.Name] > 1) {
                        this.alert('会议议题不能重复！')
                        return false;
                    }

                    const fileNames = {}
                    for (let j = 0; j < s.Files.length; j++) {
                        const f = s.Files[j];

                        if (!fileNames[f.FileName]) fileNames[f.FileName] = 0;
                        fileNames[f.FileName]++;
                        if (fileNames[f.FileName] > 1) {
                            this.alert('文件' + f.FileName + '重复上传！')
                            return false;
                        }
                    }
                }
                return entityData;
            },
            getDefaultRowData() {
                return {
                    UserCountName: '列席人员 0',
                    IsOpen: 1,
                    FileCount: '0项文件',
                    SubjectId: Common.createGuid()
                }
            },
            successCallback() {
                this.alertSuccess('保存成功！', () => {
                    if (!this.isBook) {
                        this.webSocket.send('refreshMeetingSubjects', { MeetingId: this.pageData.MeetingId });
                        this.replacePage('/meetingSubjectList.html?MeetingId=' + this.pageData.MeetingId);
                        return;
                    }
                    if (this.pageData.backUrl2) this.replacePage('/myMeeting.html');
                    else this.replacePage('/bookMeetingList.html');
                });
            },
            successCallback2() {
                this.alertSuccess('保存成功！', () => {
                    this.toPage('/meetingRoomLayout.html?ref=2&IsBook=true&MeetingId=' + this.pageData.MeetingId + "&backUrl2=" + encodeURIComponent(this.pageData.backUrl2 || ''));
                });
            }
        }
    });
})(window.aopc);